package cn.wolfcode.web.controller;

import cn.wolfcode.common.constants.CommonConstants;
import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.UserLogin;
import cn.wolfcode.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private IUserService userService;

    /**
     * 注册
     * @param userLogin
     * @param request
     * @return
     */
    @PostMapping
    public Result<Object> register(@RequestBody UserLogin userLogin, HttpServletRequest request) {
        String ip = request.getHeader(CommonConstants.REAL_IP);     // 获取网关传递的 真实 ip

        userService.register(userLogin.getPhone(), userLogin.getPassword(), ip);
        return Result.success("注册成功!", null);
    }
}
